package web.ipcdemo.controllers;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;

import com.liferay.portal.kernel.util.ParamUtil;



@Controller
@RequestMapping("VIEW")
public class PRPHandlerController {
	
	@Autowired
	private IPCDemoBean ipcdemo;

	
	public IPCDemoBean getIpcdemo() {
		return ipcdemo;
	}

	public void setIpcdemo(IPCDemoBean ipcdemo) {
		this.ipcdemo = ipcdemo;
	}

	@RenderMapping(params = "action=prp")
	public String handleRenderRequest(Model model, RenderRequest renderRequest){
		
		 if (!model.containsAttribute("demo")) {
	            model.addAttribute("demo", ipcdemo);
	        }
		return "prp";
	}
	
	@ActionMapping(params="action=setPRP")
	public void handleRenderRequest(@ModelAttribute("demo") IPCDemoBean command, BindingResult result,
            SessionStatus status, ActionResponse response,ActionRequest actionRequest) throws IOException, PortletException {

		//String sayHello = ParamUtil.getString(actionRequest, "sayHello");
		
		//System.out.println("I am here in sayHello ==> " + sayHello);
		
		//response.setRenderParameter("HELLO_TO",sayHello);/* For PRP .................
		/*PortletSession portletSession = actionRequest.getPortletSession();
		portletSession.setAttribute("HELLO_TOKEN", sayHello, PortletSession.APPLICATION_SCOPE);*/

				
		}
	
}
